package cn.wolfcode.luowowo.acticle.domain;

import cn.wolfcode.luowowo.common.domain.BaseDomain;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 目的地(行政地区：国家/省份/城市)
 */
@Setter
@Getter
public class Destination extends BaseDomain {

    public static final boolean STATE_HOT = true;
    public static final boolean STATE_NORMAL = false;

    private String name;        //名称
    private String english;  //英文名
    private String pinyin;      //中文拼音
    private Destination parent; //上级目的地
    private Region region;  //所属区域， 仅国家有
    private boolean ishot = STATE_NORMAL;         //是否为热点
    private String info;    //简介
    private int clicknum;      //点击次数
    private int deep; //层级
    private String coverUrl; //封面

    ///////////////////////////////////////
    private Integer travelDays; //旅行天数
    private String travelTime; //旅行时间
    private List<CityScenic> scenics; //地区景点

    public List<Long> getTravelTimes() {
        //从数据库拿出的id拼接字符串转换成数组
        ArrayList<Long> list = new ArrayList<>();
        if (StringUtils.isNotBlank(travelTime)) {
            String[] strs = travelTime.split(",");
            if(strs.length >0 && strs[0] != ""){
                for (int i = 0; i < strs.length; i++) {
                    if(strs[i] != ""){
                        System.out.println(strs[i]);
                        list.add(Long.parseLong(strs[i]));
                    }
                }
            }
        }
        return list;
    }

    public String getJsonString() {
        Map<String, Object> map = new HashMap<>();
        map.put("info", info);
        map.put("id", id);
        return JSON.toJSONString(map);
    }

    public String getHotDisplay() {
        return ishot ? "是" : "否";
    }

    //子地区
    private List<Destination> children = new ArrayList<>();
}